package com.zc.redisson.delayedQueue.message;

import org.springframework.lang.NonNull;
import org.springframework.util.Assert;

import java.io.Serializable;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

/**
 * @description 延时消息
 */

public class DelayMessage<T> implements Serializable {
    private static final long serialVersionUID = 9006297630420423520L;

    /**
     * 内容
     */
    private T body;

    /**
     * 消息类型
     */
    @NonNull
    private DelayMessageType type;

    private Long expire;

    private TimeUnit timeUnit;


    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        DelayMessage that = (DelayMessage) o;
        return Objects.equals(body, that.body) &&
                type == that.type;
    }

    @Override
    public int hashCode() {
        return Objects.hash(body, type);
    }

    public void setExpire(Long expire) {
        this.expire = expire;
    }

    public Long getExpire() {
        return expire;
    }

    public void setTimeUnit(TimeUnit timeUnit) {
        this.timeUnit = timeUnit;
    }

    public TimeUnit getTimeUnit() {
        return timeUnit;
    }



    public void check() {
        Assert.notNull(this.body, "delay message must not be null");
        Assert.notNull(this.type, "delay message type must not be null");
    }

    @NonNull
    public T getBody() {
        return body;
    }

    public void setBody(@NonNull T body) {
        this.body = body;
    }

    @NonNull
    public DelayMessageType getType() {
        return type;
    }

    public void setType(@NonNull DelayMessageType type) {
        this.type = type;
    }


}
